package com.yingxin.yxerp.module.common;

import com.yingxin.yx.framework.commons.enums.BusinessType;

import java.util.HashMap;
import java.util.Map;

public class BusinessTypeHelper {

    private static final Map<String, BusinessType> map = new HashMap<>();

    public static void init() {
        if (map.size() == 0) {
            for (BusinessType type : BusinessType.values()) {
                map.put(type.getType(), type);
            }
        }
    }

    public static String getName(String id) {
        init();
        BusinessType type = map.get(id);
        if (type != null) {
            return type.getTypeName();
        }
        return null;
    }


    public static BusinessType get(String id) {
        init();
        return map.get(id);
    }

    // 更新枚举
    public static void updateAll(Map<String, String> map) {
        for (BusinessType type : BusinessType.values()) {
            String name = map.get(type.getType());
            if (name != null) {
                type.setTypeName(name);
            }
        }
    }


    public static void updateOne(String key, String value) {
        BusinessType type = BusinessType.getEnum(key);
        if (type != null) {
            type.setTypeName(value);
        }
    }

}